package com.nameless.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.nameless.dao.BrandDao;
import com.nameless.dao.CarCommentDao;
import com.nameless.entity.Brand;
import com.nameless.entity.Car;
import com.nameless.entity.CarComment;
import com.nameless.entity.Client;
import com.nameless.feign.CarFeign;
import com.nameless.feign.ClientFeign;
import com.nameless.service.CarCommentService;
import com.nameless.vo.CarCommentVo;
import com.nameless.vo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author keluoyisi
 * @program: car-parent
 * @description:
 * @date 2023-02-27 20:14:04
 */
@Service
@SuppressWarnings("all")
public class CarCommentServiceImpl  extends ServiceImpl<CarCommentDao, CarComment> implements CarCommentService {
    @Autowired
    private CarCommentDao carCommentDao;

    @Autowired
    private CarFeign carFeign;

    @Autowired
    private ClientFeign clientFeign;
    @Override
    public Result queryAllByParam(CarCommentVo carCommentVo) {
        PageHelper.startPage(carCommentVo.getPageNo(),carCommentVo.getPageSize());
        QueryWrapper<CarComment> wrapper = new QueryWrapper<>();
        if (carCommentVo.getClientName()!=null){
            Client client = clientFeign.selectName(carCommentVo.getClientName());
            wrapper.eq("client_id",client.getId());
        }
        if (carCommentVo.getCarName()!=null){
            Car car = carFeign.selectName(carCommentVo.getCarName());
            wrapper.eq("carId",car.getId());
        }

        List<CarComment> list = carCommentDao.selectList(wrapper);
        for (CarComment carComment : list) {
            carComment.setCarName(carFeign.selectId(carComment.getCarId()).getCarName());
            carComment.setClientName(clientFeign.selectId(carComment.getClientId()).getName());
        }
        PageInfo<CarComment> carCommentPageInfo = new PageInfo<>(list);
        return new Result(200,"成功",carCommentPageInfo);
    }

    @Override
    public Result deleteById(Integer id) {
        int i = carCommentDao.deleteById(id);
        return new Result(200,"成功");
    }
}
